home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-28 | 26.9 KB | 1,060 lines | [TEXT/MMCC] |
- // This is based on the sample code on the QuickTime 1.5 CD ROM
- //
- // Movie controller components allow you to create an action filter function in your
- // application. The component calls your action filter function whenever an action
- // occurs in the control. (An action is an integer constant used by the movie controller
- // omponent.) You can then customize the behavior of the control or simply monitor user
- // actions. You establish an action filter function by calling the MCSetActionFilter
- // function.
- //
- // This code demonstrates the use of an action filter function, and handles
- // mouse down events in the content region of the movie window, allowing a user to
- // navigate in the movie by dragging left and right. This filter function
- // resizes the window whenever the user hides the controller. Therefore, this example
- // function handles the mcActionControllerSizeChanged action. Your application should
- // include a similar action filter function so that you can determine when the user
- // resizes the controller.
- //
- // The code also gets around a QuickTime 2.0 problem with the drag manager
- //
- // MCDoAction( aController, mcActionSetDragEnabled, (void *)false) ;
- //
- // does not work quite as expected, the DoIgnoreDrags() workaround lets us ignore
- // both dragging and dropping
- //
- // 10/10/94 nick stripped code from the text media example
- // 10/17/94 nick added an MCActionProc, this allows you to move backwards
- // and forwards through the movie by dragging left and right on
- // the movie.
- // 10/18/94 nick added code to turn off drag manager support in QT 2.0
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
-
- #include "mtb.h"
- #include "QDOffscreen.h"
- #include <FixMath.h>
-
- void AdornWindow( WindowPtr whichWindow, const RGBColor *adornerColor ) ;
- void DoCreateMovieWindow( void ) ;
- void DoDestroyMovieWindow( WindowPtr aWindow ) ;
- void MainEventLoop( void ) ;
- void InitMac( void ) ;
- Boolean IsAppWindow(WindowPtr window) ;
- void HandleKeyPress( EventRecord *event ) ;
- void HandleMenuCommand(long menuResult ) ;
- void AdjustMenus( void ) ;
-
- Track GetFirstTrackOfType( Movie aMovie, OSType trackType ) ;
- OSErr DoPrerollMovie( Movie aMovie ) ;
- pascal Boolean myMCActionFilter(MovieController mc, short action, void *params, long refCon) ;
- void DoSelectActive( WindowPtr whichWindow ) ;
- void DoAdjustCursor( Point mouse, RgnHandle region, WindowPtr window) ;
- OSErr DoIgnoreDrags( MovieController aController ) ;
-
- #define HiWrd(aLong) (((aLong) >> 16) & 0xFFFF)
- #define LoWrd(aLong) ((aLong) & 0xFFFF)
-
-
- //---------------------------------------------------------------------------
- // define a record to hold the information we need for each movie window.
- // The movie can be gotten from the movieController
- //---------------------------------------------------------------------------
-
- typedef struct {
- MovieController myController ;
- } DocumentRecord, *DocumentPtr, **DocumentHandle ;
-
- //---------------------------------------------------------------------------
-
- static Boolean gQuitFlag = false ; // set to true when we want to quit
-
- const RGBColor kWindowBGColor = {0xFF00, 0xFF00, 0xFF00} ; // grays made the caret yellow, ughh, need to investigate this
- const RGBColor kRGBBlack = {0x0000, 0x0000, 0x0000} ;
- const RGBColor kRGBGray = {0xAAAA, 0xAAAA, 0xAAAA} ;
- const RGBColor kRGBWhite = {0xFFFF, 0xFFFF, 0xFFFF} ;
-
- const Rect kDefaultWinRect ;
- const short kSlopMargin = 8 ;
-
-
-
- //---------------------------------------------------------------------
- //
- // menus and items...
-
- enum {
- mApple = 128,
- mFile,
- mEdit
- } ;
-
- enum {
- iAbout = 1
- } ;
- enum {
- iOpen = 1,
- iClose,
- iUnused1,
- iSaveAs = 4,
- iUnused2,
- iQuit
-
- } ;
-
- enum {
- iUndo = 1,
- iCut = 3,
- iCopy,
- iPaste,
- iClear,
- iSelectAll = 8
- } ;
-
- //---------------------------------------------------------------------
-
- DocumentHandle CreateDocumentHandle( WindowPtr aWindow )
- {
- DocumentHandle theHandle ;
-
- theHandle = (DocumentHandle)NewHandle( sizeof(DocumentRecord)) ;
- if( theHandle != nil ) {
-
- // make sure we init the doc record fields to sensible values.
-
- (**theHandle).myController = nil ;
-
- // store a reference to the document record for this window
- // in the refcon field of this window.
- SetWRefCon ( aWindow, (long)theHandle );
-
- }
-
- return theHandle ;
- }
-
- //---------------------------------------------------------------------
-
- WindowPtr CreateMovieWindow( Rect *aRect, Str255 theTitle )
- {
- WindowPtr aWindow ;
-
- // create a window for the movie
- aWindow = NewCWindow(nil,
- aRect,
- theTitle,
- false,
- noGrowDocProc,
- (WindowPtr)-1,
- true,
- 0 ) ;
-
- // restore current port
- return aWindow ;
- }
-
- //---------------------------------------------------------------------
- // turn off drag manager support
-
- OSErr DoIgnoreDrags( MovieController aController )
- {
- // these two are used to hack the drag manager support
- GWorldPtr tempGWorld ;
- Rect tempRect = { 0,0, 20,20} ;
- OSErr myErr = noErr ;
- CGrafPtr port ;
- GDHandle gdh ;
-
- // the following code gets around a QuickTime 2.0 problem
- // with the drag manager
- //
- // MCDoAction( aController, mcActionSetDragEnabled, (void *)false) ;
- //
- // does not work quite as expected, the following workaround lets us ignore
- // both dragging and dropping
-
- // set up so we ignore drags
- if((myErr = NewGWorld( &tempGWorld, 1, &tempRect, nil, nil, 0L )) == noErr)
- {
- // get the current port
- port = MCGetControllerPort( aController ) ;
-
- // set the movie controller port to the new offscreen
- MCSetControllerPort( aController, (CGrafPtr)tempGWorld ) ;
-
- // tell 'em we don't want drags
- MCDoAction( aController, mcActionSetDragEnabled, (void *)false) ;
-
- // restore the movie controller port
- MCSetControllerPort( aController, port ) ;
-
- // ditch the offscreen
- DisposeGWorld( tempGWorld ) ;
- }
-
- return myErr ;
- }
-
- //---------------------------------------------------------------------
-
- MovieController SetUpMovieWindowWithController( WindowPtr aWindow )
- {
- Movie aMovie ; // the movie in question
- MovieController aController; // the controller for this movie
- Rect aRect ; // bounding rect of the movie
- GrafPtr savedPort ; // used to reset the current port
- DocumentHandle aDocHdl ;
- short movieWidth ;
- short movieHeight ;
- Boolean boolValue = false ;
-
-
- aDocHdl = (DocumentHandle)GetWRefCon( aWindow ) ;
-
- // save whatever the port was before we go in here
- GetPort( &savedPort ) ;
-
- // get the movie to open
- aMovie = GetMovie () ;
-
- // sanity check
- if( aMovie == nil )
- CheckError( paramErr, "\pSetUpMovieWindowWithController was passed nil for aMovie") ;
-
- SetPort( (GrafPtr)aWindow ) ;
-
- // set the movies environment to the current
- // port and gDevice (pass nil for defaults)
- SetMovieGWorld( aMovie, nil, nil ) ;
-
- // Use the movie bounding rect to size the movie
- GetMovieBox( aMovie, &aRect );
- OffsetRect( &aRect, -aRect.left, -aRect.top ) ;
- SetMovieBox( aMovie, &aRect );
-
- // create a movie controller for the movie
- aController = NewMovieController (aMovie, &aRect, 0L | mcTopLeftMovie );
-
- MCGetControllerBoundsRect(aController,&aRect) ;
-
- // lets make sure the movie bounds are reasonable
- movieWidth = aRect.right - aRect.left ;
- movieHeight = aRect.bottom - aRect.top ;
- aRect.top = aRect.left = 0 ;
- aRect.right = movieWidth ;
- aRect.bottom = movieHeight ;
-
- // size the window accordingly
- SizeWindow( aWindow, movieWidth, movieHeight, true ) ;
- MoveWindow( aWindow, 50, 50, false ) ;
-
- // should have some error handling here
- if (aController == nil)
- ExitToShell();
-
- // install our event filter
-
- MCSetActionFilterWithRefCon( aController, NewMCActionFilterWithRefConProc(myMCActionFilter), 0L) ;
-
- // store the controller in the document record
- (**aDocHdl).myController = aController ;
-
- DoIgnoreDrags( aController ) ;
-
- SetPort( savedPort ) ;
- return aController ;
- }
-
-
- //---------------------------------------------------------------------
-
- void DoCreateMovieWindow()
- {
- Rect aRect = kDefaultWinRect ;
- Rect controlRect ; // for the push button control
- WindowPtr aWindow;
- Track aTrack ;
- ControlHandle aControl ;
- MovieController aController ;
- DocumentHandle theDocHandle ;
- GrafPtr savedPort ;
-
-
- GetPort( &savedPort ) ;
-
- // create the window
- aWindow = CreateMovieWindow( &aRect, "\pA Movie" ) ;
- SetPort( (GrafPtr)aWindow ) ;
-
- if( aWindow == nil )
- CheckError( -1, "\pCouldn't create window") ;
-
- // set up our document handle in the refcon field of the window
- theDocHandle = CreateDocumentHandle( aWindow ) ;
- if( theDocHandle == nil )
- CheckError( MemError(), "\pCouldn't allocate memory") ;
-
-
- // set up the movie for the window
- aController = SetUpMovieWindowWithController( aWindow ) ;
-
- // finally show the window.
- ShowWindow ( aWindow );
-
- //
- InvalRect( &((GrafPtr)aWindow)->portRect ) ;
-
- // set up the edit menu
- MCEnableEditing( aController, true ) ;
-
- SetPort( savedPort ) ;
-
- }
-
- //---------------------------------------------------------------------
-
- OSErr DoPrerollMovie( Movie aMovie )
- {
- TimeValue aTimeValue ;
- TimeValue movieDur ;
- Fixed preferredRate ;
- OSErr theErr = noErr ;
-
- aTimeValue = GetMovieTime(aMovie, nil);
- movieDur = GetMovieDuration(aMovie);
- preferredRate = GetMoviePreferredRate(aMovie);
-
- if (aTimeValue == movieDur)
- aTimeValue = 0;
-
- theErr = PrerollMovie(aMovie, aTimeValue, preferredRate);
-
- return theErr ;
- }
-
- //---------------------------------------------------------------------
-
- void DoDestroyMovieWindow( WindowPtr aWindow )
- {
- Movie aMovie ;
- MovieController aController ;
- DocumentHandle aDocHdl ;
-
- aDocHdl = (DocumentHandle)GetWRefCon( aWindow ) ;
- aController = (**aDocHdl).myController ;
-
- if( aController != nil ) {
- aMovie = MCGetMovie( aController ) ;
- if( aMovie != nil ) {
- DisposeMovie (aMovie);
- }
- DisposeMovieController (aController);
- }
-
- DisposeWindow(aWindow);
- }
-
- //---------------------------------------------------------------------
-
- Boolean PointInMovieController( MovieController aController, WindowPtr whichWindow, Point where)
- {
- RgnHandle rgn ;
- Boolean result = false ;
-
- rgn = MCGetWindowRgn( aController, whichWindow ) ;
- if( rgn != nil ) {
- result = PtInRgn( where, rgn ) ;
- DisposeRgn( rgn ) ;
- }
- return result ;
- }
-
-
-
- //---------------------------------------------------------------------
-
- void HandleContentClick( WindowPtr whichWindow, EventRecord *theEvent )
- {
- GrafPtr oldPort ;
- // stub
-
- GetPort(&oldPort ) ;
- SetPort( whichWindow );
-
- SetPort( oldPort ) ;
- }
-
- //---------------------------------------------------------------------
-
- void MyDoIdle( WindowPtr whichWindow )
- {
- GrafPtr oldPort ;
- DocumentHandle aDocHdl ;
- MovieController aController = nil;
-
- GetPort(&oldPort ) ;
- SetPort( whichWindow );
-
- if((aDocHdl = (DocumentHandle)GetWRefCon( whichWindow )) != nil )
- if((aController = (**aDocHdl).myController) != nil)
- MoviesTask( MCGetMovie(aController), 0);
-
- SetPort( oldPort ) ;
-
- }
-
- //---------------------------------------------------------------------
-
- void DoActivateWindow( WindowPtr whichWindow, Boolean becomingActive)
- {
- DocumentHandle aDocHdl ; // our document record is stuffed in the window refcon
- MovieController aController ;
- GrafPtr savedPort ;
-
- GetPort(&savedPort) ;
- SetPort((GrafPtr)whichWindow) ;
-
- if((aDocHdl = (DocumentHandle)GetWRefCon(whichWindow)) != nil)
- if((aController = (**aDocHdl).myController) != nil )
- MCActivate( aController, whichWindow, becomingActive ) ;
-
- SetPort(savedPort) ;
- }
-
-
-
- //---------------------------------------------------------------------
-
- void DoUpdateWindow( WindowPtr whichWindow, Rect *refreshArea )
- {
- GrafPtr savedPort ;
-
- GetPort(&savedPort ) ;
- SetPort( whichWindow );
-
- BeginUpdate (whichWindow);
-
- // draw whatever in here, as the movie controller handles updates for the movie
- // and the controller, we don't have anything else in the window to update
-
- EndUpdate (whichWindow);
- SetPort( savedPort ) ;
-
- }
-
- //---------------------------------------------------------------------
-
- void MainEventLoop( void )
- {
- OSErr err;
- EventRecord theEvent;
- WindowPtr whichWindow, theWindow;
- short part;
- short controlPart ;
- ControlHandle aControl ;
- Boolean wasMovieEvent ;
- MovieController aController ;
- Point aPoint = {100, 100};
- Rect refreshArea ;
- Rect screenRect ;
- GrafPtr oldPort ;
-
- DocumentHandle aDocHdl ;
- Boolean myMovieIsActive ;
-
-
- // use this in calls to MCDoAction
- long myMCActionParams ;
- RgnHandle cursorRgn = NewRgn() ;
-
- while (!gQuitFlag) {
-
-
- AdjustMenus() ;
- DoAdjustCursor( theEvent.where, cursorRgn, FrontWindow() ) ;
-
- wasMovieEvent = false ;
-
- WaitNextEvent(everyEvent, &theEvent, 0, nil );
-
- for( theWindow = FrontWindow(); theWindow != nil ; theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow)
- if(( aDocHdl = (DocumentHandle)GetWRefCon( theWindow )) != nil)
- if( (aController = (**aDocHdl).myController) != nil )
- if(MCIsPlayerEvent(aController, &theEvent))
- wasMovieEvent = true ;
-
- // if the controller didn't or couldn't handle it
- // we need to handle it in the main event loop.
-
- if (!wasMovieEvent) {
-
- switch (theEvent.what) {
-
- case mouseDown:
-
- part = FindWindow (theEvent.where, &whichWindow);
-
- switch (part) {
-
- case inMenuBar:
- HandleMenuCommand(MenuSelect(theEvent.where));
- break;
-
- case inDrag:
- {
- Rect r;
- Movie aMovie ;
- MovieController aController ;
- DocumentHandle aDocHdl ;
-
- aDocHdl = (DocumentHandle)GetWRefCon( whichWindow ) ;
- aController = (**aDocHdl).myController ;
-
- aMovie = MCGetMovie(aController) ;
-
-
- GetMovieBox(aMovie, &r);
- screenRect = (**GetGrayRgn()).rgnBBox;
- DragAlignedWindow(whichWindow, theEvent.where, &screenRect, &r, nil);
- }
- break;
-
- case inContent:
-
- HandleContentClick( whichWindow, &theEvent ) ;
- break ;
-
- case inGoAway:
-
- // if the window got closed, dispose of our movie
- // and the controller and the window.
-
- if( TrackGoAway (whichWindow, theEvent.where ))
- DoDestroyMovieWindow( whichWindow ) ;
-
- break;
- }
- break ;
-
- case updateEvt:
-
- whichWindow = (WindowPtr)theEvent.message;
- refreshArea = ((**(whichWindow->visRgn)).rgnBBox);
- DoUpdateWindow( whichWindow, &refreshArea ) ;
- break;
-
- case keyDown:
- case autoKey:
- HandleKeyPress(&theEvent);
- break;
-
- case diskEvt:
- if ( HiWrd(theEvent.message) != noErr )
- (void) DIBadMount(aPoint, theEvent.message);
- break;
-
- case activateEvt:
- // so are we becoming active?
- whichWindow = (WindowPtr)theEvent.message ;
- if( IsAppWindow(whichWindow)) {
- DoActivateWindow( whichWindow, ((theEvent.modifiers & activeFlag) != 0)) ;
- }
- break;
-
- case osEvt:
- switch ((theEvent.message >> 24) & 0x00FF) { // High byte of message
- case suspendResumeMessage:
- if (FrontWindow()) {
- DoActivateWindow(FrontWindow(), !((theEvent.message & resumeFlag) == 0));
- }
- break;
-
- case mouseMovedMessage:
- break;
- }
- break;
-
- case nullEvent:
- if(( whichWindow = FrontWindow()) != nil )
- MyDoIdle( whichWindow ) ;
- break ;
-
- }
- }
- }
- DisposeRgn( cursorRgn ) ;
- }
-
- //---------------------------------------------------------------------
-
- Boolean IsAppWindow(WindowPtr window)
- {
- short windowKind;
-
- if ( window == nil )
- return false;
- else {
- windowKind = ((WindowPeek) window)->windowKind;
- return ((windowKind >= userKind) || (windowKind == dialogKind));
- }
- }
-
- //---------------------------------------------------------------------
-
- void AdjustMenus( void )
- {
- WindowPtr theWindow ;
- MenuHandle editMenu ;
- MovieController aController ;
- DocumentHandle aDocHdl ;
-
-
-
- theWindow = FrontWindow() ;
-
- if( theWindow != nil ) {
- EnableItem ( GetMHandle ( mFile ), iClose );
-
- // The edit menu - let the movie controller setting it up
- if((aDocHdl = (DocumentHandle)GetWRefCon( theWindow )) != nil )
- {
- if(aController = (**aDocHdl).myController) {
- MenuHandle editMenu = GetMHandle( mEdit ) ;
- MCSetUpEditMenu(aController, 0L, GetMHandle ( mEdit ) ) ;
- }
- }
- }
- else {
- DisableItem ( GetMHandle ( mFile ), iClose );
- }
- DisableItem ( GetMHandle ( mEdit ), 0 );
-
- }
-
-
- //---------------------------------------------------------------------
-
- void HandleKeyPress(EventRecord *event)
- {
- char key;
-
- key = event->message & charCodeMask;
-
- if ( event->modifiers & cmdKey ) { // Command key down?
- HandleMenuCommand(MenuKey(key));
- }
- }
-
-
- //---------------------------------------------------------------------
-
- void HandleMenuCommand(long menuResult)
- {
- short menuID;
- short menuItem;
- Str255 daName;
- DialogPtr theDialog ;
- short itemHit ;
- FSSpec theFSSpec ;
- OSErr err ;
- short theRef ;
-
- Movie aMovie = nil;
- MovieController aController ;
-
- StandardFileReply theSFReply ;
- DocumentHandle aDocHdl ;
- WindowPtr aWindow ;
- OSErr theErr ;
-
-
- menuID = HiWrd(menuResult);
- menuItem = LoWrd(menuResult);
- switch ( menuID ) {
- case mApple:
- switch ( menuItem ) {
- case iAbout:
- theDialog = GetNewDialog ( 128, nil, (WindowPtr)-1 );
- SetDialogDefaultItem(theDialog, 1) ;
-
- do {
- ModalDialog ( nil, &itemHit );
- } while( itemHit != ok ) ;
- DisposDialog ( theDialog );
- break;
-
- default:
- GetItem(GetMHandle(mApple), menuItem, daName);
- (void) OpenDeskAcc(daName);
- break;
- }
- break;
-
- case mFile:
- switch ( menuItem ) {
- case iOpen:
- DoCreateMovieWindow();
- break ;
-
- case iClose:
- DoDestroyMovieWindow( FrontWindow() ) ;
- break ;
-
- case iSaveAs:
-
-
- // get the name of the file to save as
- StandardPutFile("\pSave movie as:", "\pNew Movie File", &theSFReply) ;
-
- if( theSFReply.sfGood ) {
-
- // get the movie for this window
- aDocHdl = (DocumentHandle)GetWRefCon( FrontWindow() ) ;
- aController = (**aDocHdl).myController ;
-
- if( aController != nil ) {
- aMovie = MCGetMovie(aController) ;
- }
- else {
- CheckError( -1, "\pCouldn't get movie controller") ;
- }
-
- if( aMovie != nil ) {
-
- FlattenMovieData( aMovie, flattenAddMovieToDataFork, &theSFReply.sfFile, 'TVOD', smSystemScript, createMovieFileDeleteCurFile ) ;
-
- theErr = GetMoviesError() ;
- CheckError( theErr, "\pCouldn't FlattenMovieData") ;
-
-
- }
-
- }
- break ;
-
- case iQuit:
- gQuitFlag = true;
- break;
- }
- break;
-
- case mEdit:
-
- if((aWindow = FrontWindow()) != nil ) {
- aDocHdl = (DocumentHandle)GetWRefCon(aWindow) ;
- aController = (**aDocHdl).myController ;
- }
-
- switch ( menuItem ) {
-
- case iUndo:
- MCUndo( aController ) ;
- break ;
-
- case iCut:
- aMovie = MCCut( aController ) ;
- break ;
-
- case iCopy:
- aMovie = MCCopy( aController ) ;
- break ;
-
- case iPaste:
- MCPaste( aController, nil ) ;
- break ;
-
- case iClear:
- MCClear( aController ) ;
- break ;
-
- case iSelectAll:
- break ;
- }
- if( aMovie ) {
- PutMovieOnScrap( aMovie, 0) ;
- DisposeMovie( aMovie ) ;
- }
- break ;
-
- }
- HiliteMenu(0); // Unhighlight whatever MenuSelect or MenuKey hilited
- }
-
- //---------------------------------------------------------------------
-
- void InitMac( void )
- {
- Handle menuBar = nil;
-
- // we want to grow the heap as big as possble, or the text media handler may not
- // load the text track properly initially
-
- MaxApplZone();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
-
- InitGraf (&qd.thePort);
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs ((long)nil);
-
- if (!IsQuickTimeInstalled()) {
- CheckError(-1,"\pPlease install QuickTime and try again.");
- }
-
- CheckError( EnterMovies (), "\pEnterMovies failed" );
-
- // get the menu bar
-
- menuBar = GetNewMBar(128); // Read menus into menu bar, MBAR res id is 128
-
- if ( menuBar == nil )
- ExitToShell(); // if we dont have it then quit - your app
- // needs a dialog here
-
- SetMenuBar(menuBar); // Install menus
- DisposHandle(menuBar);
-
- AddResMenu(GetMHandle(mApple), 'DRVR'); // Add DA names to Apple menu, ID 128
-
- DrawMenuBar();
-
-
- gQuitFlag = false ; // set the flag for the main event loop
- }
-
- //---------------------------------------------------------------------
-
- // locate the first track in a movie with the supplied type
- Track GetFirstTrackOfType( Movie aMovie, OSType trackType )
- {
- Track theTrack = nil ;
- OSType mediaType;
- short trackCount ;
- short index ;
-
- trackCount = GetMovieTrackCount(aMovie);
- for ( index=1 ; index <= trackCount ; index++) {
- Track t = GetMovieIndTrack(aMovie, index);
-
- GetMediaHandlerDescription(GetTrackMedia(t), &mediaType, nil, nil);
- if (mediaType == trackType) {
- theTrack = t;
- break;
- }
- }
-
- return theTrack ;
-
- }
-
-
- //---------------------------------------------------------------------
- // set the cursor to the correct shape,
- // according to the current location
-
- void DoAdjustCursor( Point mouse, RgnHandle region, WindowPtr window)
- {
- RgnHandle arrowRegion, handRegion ;
- Rect handRect ;
- Point handTopLeft, handBotRight ;
- DocumentHandle aDocHdl ;
-
-
- Movie aMovie ;
- MovieController aController ;
-
- if( window != nil ) {
-
- // get the movie controller reference from the
- // RefCon field of the window
-
- if(( aDocHdl = (DocumentHandle)GetWRefCon( window )) != nil) {
- if( (aController = (**aDocHdl).myController) != nil ) {
-
-
- // get the movie reference from the controller
- aMovie = MCGetMovie( aController ) ;
- GetMovieBox( aMovie, &handRect );
-
- arrowRegion = NewRgn() ;
- handRegion = NewRgn() ;
-
- // make the arrow region huge
- SetRectRgn(arrowRegion, -32768, -32768, 32766, 32766 ) ;
-
- // calculate the region for the hand
-
- SetPort( window ) ;
-
- handTopLeft.h = handRect.left ;
- handTopLeft.v = handRect.top ;
- handBotRight.h = handRect.right ;
- handBotRight.v = handRect.bottom ;
-
- LocalToGlobal( &(handTopLeft)) ;
- LocalToGlobal( &(handBotRight)) ;
-
- handRect.left = handTopLeft.h ;
- handRect.top = handTopLeft.v ;
- handRect.right = handBotRight.h ;
- handRect.bottom = handBotRight.v ;
-
- RectRgn( handRegion, &handRect ) ;
-
- SetOrigin( -(window->portBits.bounds.left), -(window->portBits.bounds.left)) ;
- SetOrigin( 0, 0 ) ;
-
- // the arrow region is everything else
- DiffRgn( arrowRegion, handRegion, arrowRegion ) ;
-
- if(PtInRgn( mouse, handRegion )) {
- Cursor handCsr ;
- CursHandle handCursH ;
-
- handCursH = GetCursor ( 1024 ) ;
- handCsr = **handCursH ;
-
- SetCursor( &handCsr ) ;
- CopyRgn( handRegion, region ) ;
- }
-
- if(PtInRgn( mouse, arrowRegion )) {
- SetCursor( &qd.arrow ) ;
- CopyRgn( arrowRegion, region ) ;
- }
-
- DisposeRgn( arrowRegion ) ;
- DisposeRgn( handRegion ) ;
- }
- }
- }
- }
-
- //---------------------------------------------------------------------
- // Movie controller components allow you to create an action filter function in your
- // application. The component calls your action filter function whenever an action
- // occurs in the control. (An action is an integer constant used by the movie controller
- // omponent.) You can then customize the behavior of the control or simply monitor user
- // actions. You establish an action filter function by calling the MCSetActionFilter
- // function.
- //
- // This code demonstrates the use of an action filter function. This filter function
- // resizes the window whenever the user hides the controller. Therefore, this example
- // function handles the mcActionControllerSizeChanged action. Your application should
- // include a similar action filter function so that you can determine when the user
- // resizes the controller. This function only supports attached controllers.
- //
-
- pascal Boolean myMCActionFilter(MovieController mc, short action, void *params, long refCon)
- {
- RgnHandle controllerRgn;
- Rect controllerBox;
- WindowPtr movieWindow;
- OSErr err ;
-
- switch ( action ) {
-
- case mcActionControllerSizeChanged:
-
- /* size of controller/movie has changed */
-
- movieWindow = (WindowPtr)MCGetControllerPort(mc);
- controllerRgn = MCGetWindowRgn(mc, movieWindow);
- if (controllerRgn != nil) {
- controllerBox = (**controllerRgn).rgnBBox;
- DisposeRgn (controllerRgn);
- SizeWindow (movieWindow, controllerBox.right,
- controllerBox.bottom, true);
- }
-
- break;
-
- case mcActionMouseDown:
- {
- EventRecord *event;
- Rect contentArea ;
- Boolean goLeft ; // rotate the movie left
- Rect controllerRect ; // the rect occupied by the controller
-
- Movie aMovie ;
-
- // get the movie reference from the controller
- aMovie = MCGetMovie( mc ) ;
- GetMovieBox( aMovie, &contentArea );
-
- event = (EventRecord *)params ;
-
- // check to see if we clicked in the controller itself
- // this will break if the controller is non rectangular
-
- movieWindow = (WindowPtr)MCGetControllerPort(mc);
- controllerRgn = MCGetWindowRgn( mc, movieWindow );
- if (controllerRgn != nil) {
- controllerBox = (**controllerRgn).rgnBBox;
-
- // here is the box containing the controller, use this for hit testing on the controller
- controllerRect.top = contentArea.bottom ;
- controllerRect.left = 0 ;
- controllerRect.bottom = controllerBox.bottom ;
- controllerRect.right = controllerBox.right ;
-
- // we only want to process the event iff the event was
- // NOT in the movie controller for this movie
-
- if(! PtInRect ( event->where, &controllerRect ) ) {
-
- // set our cursor to the grabber
- Cursor handCsr ;
- CursHandle handCursH ;
-
- handCursH = GetCursor ( 1025 ) ;
- handCsr = **handCursH ;
-
- SetCursor( &handCsr ) ;
-
- do {
-
-
- // i guess the user clicked in the content region of the movie
- goLeft = (event->where.h > (contentArea.right / 2)) ;
-
- if( goLeft ) {
- // want to step one frame back
- err = MCDoAction (mc, mcActionStep, (Ptr) (-1L));
- }
- else {
- err = MCDoAction (mc, mcActionStep, (Ptr) (1L));
- }
-
- // draw the next frame
-
- err = MCDoAction (mc, mcActionDraw, (Ptr) movieWindow);
- GetMouse( &(event->where)) ;
-
- } while( StillDown()) ;
-
- event = nil ;
- }
- DisposeRgn (controllerRgn);
- }
- }
- break ;
- }
- return false;
- }
-
-
- //---------------------------------------------------------------------
- // main - entry point for the app.
-
- void main (void)
- {
- InitMac() ;
- MainEventLoop() ;
- }
-